package num98;

import java.util.ArrayList;

/**
 * @author : DuJiabao
 * @Date : 2021/2/6 16:20
 * @Project : sword-finger-offer
 * @File : null.java
 * @Desc :
 */
public class Solution {
    public boolean isValidBST(TreeNode root) {
        ArrayList<Integer> arrayList = inOrder(root);
        for (int i = 1; i < arrayList.size(); i++) {
            if (arrayList.get(i) <= arrayList.get(i - 1)) return false;
        }
        return true;
    }

    private static ArrayList<Integer> inOrder(TreeNode node) {
        ArrayList<Integer> arrayList = new ArrayList<Integer>();
        if (node == null) return arrayList;
        arrayList.addAll(inOrder(node.left));
        arrayList.add(node.val);
        arrayList.addAll(inOrder(node.right));
        return arrayList;
    }
}
